package Array_Object;

/**
 * ClassName:GirlFriendTest
 * Package:Array_Object
 * Description:
 *
 * @Author:ZhangXin
 * @Create2023/1/15-15:13
 * @Version:v1.0
 */
public class GirlFriendTest {
    public static void main(String[] args) {
        GirlFriend[] arr = new GirlFriend[4];
        GirlFriend gf1 = new GirlFriend("小诗诗", 21, "萌妹子", "打游戏");
        GirlFriend gf2 = new GirlFriend("小丹丹", 22, "抠脚大汉", "吃零食");
        GirlFriend gf3 = new GirlFriend("小慧慧", 23, "御姐", "看书,学习");
        GirlFriend gf4 = new GirlFriend("小莉莉", 24, "萝莉", "睡觉");
        //把对象添加到数组中
        arr[0] = gf1;
        arr[1] = gf2;
        arr[2] = gf3;
        arr[3] = gf4;
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend gf = arr[i];
            sum += gf.getAge();
        }
        double avg = sum * 1.0 / arr.length;
        int count = 0;
        for (int i = 0; i < arr.length; i++) {
            GirlFriend gf = arr[i];
            if (gf.getAge() < avg) {
                count++;
                System.out.println(gf.getName() + "," + gf.getAge() + "," + gf.getGender() + "," + gf.getHobby());
            }
        }
        System.out.println("别平均年龄低的有" + count + "个");
    }
}
